package com.family.gmall.web.controller;

import com.family.gmall.common.execption.GmallException;
import com.family.gmall.common.result.Result;
import com.family.gmall.common.result.ResultCodeEnum;
import com.family.gmall.product.client.ProductFeignClient;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;

/**
 * @Auther: family
 * @Date: 2023/7/17 10:19
 * @Description:
 */
@Controller
public class IndexController {

    @Resource
    private ProductFeignClient productFeignClient;

    @RequestMapping({"/", "index.html"})
    public String index(Model model) {
        Object data = productFeignClient.getCategoryTree().getData();
        model.addAttribute("list", data);
        return "index/index";
    }

    @RequestMapping("/test/{id}")
    @ResponseBody
    public Result test(@PathVariable Long id) {
        if (id == 0) {
            throw new GmallException("非法参数", ResultCodeEnum.FAIL.getCode());
        }
        Long result = 10 / id;
        return Result.ok(result);
    }
}
